package kr.hkit.androidcomplete03.ch21;

import kr.hkit.androidcomplete03.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ShareActionProvider;
import android.widget.TextView;

public class ShareAction extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		TextView tv = new TextView(this);
		tv.setText("공유 액션 프로바이더를 테스트합니다.");
		setContentView(tv);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.shareactionmenu, menu);
		
		Intent intent = new Intent(Intent.ACTION_SEND);				// 중요
		intent.setType("text/plain");								// 일반적인 텍스트
		intent.putExtra(Intent.EXTRA_TEXT, "sharing text");			// sharing text를 공유
		
		MenuItem share = menu.findItem(R.id.share);
		
		ShareActionProvider provider = (ShareActionProvider) share.getActionProvider();
		provider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
		provider.setShareIntent(intent);
		
		MenuItem shareMenu = menu.findItem(R.id.sharemenu);
		ShareActionProvider providerMenu = (ShareActionProvider) shareMenu.getActionProvider();
		providerMenu.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
		providerMenu.setShareIntent(intent);
		
		return true;
	}

}
